package com.lry.sso.auth.common.util;


import com.lry.sso.auth.common.bean.RequestInfoContext;
import com.lry.sso.auth.common.exception.LoginError;
import com.lry.sso.common.exception.SysInvocationException;

import java.util.List;

/**
 * 
 *
 * @author 李瑞益
 * @date 2019/9/20
 */
public class SessionInfoUtil {

    public static SessionInfo getSessionInfo(){
        SessionInfo session = null;
        try {
            session = RequestInfoContext.getSession();
        } catch (Exception e) {
            throw new SysInvocationException(LoginError.LOGIN_FAIL);
        }
        return session;
    }

    /**
     * 获取用户id
     * @return 用户id
     */
    public static Long getUserId(){
        return getSessionInfo().getUserId();
    }

    /**
     * 获取当前角色id列表
     * @return 角色id列表
     */
    public static List<Integer> getCurrentRoleIdList() {
        return getSessionInfo().getRoleIdList();
    }

    /**
     * 获取当前角色权限id列表
     * @return
     */
    public static List<Integer> getCurrentPermissionIdList() {
        return getSessionInfo().getPermissionIdList();
    }
}
